<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <script src="../../script/vue.min.js"></script>
    <script src="../../script/fastclick.js"></script>
    <style type="text/css">
        html,
        body {
            height: 100%;
        }

        #wrap {
            height: 100%;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-flex-flow: column;
            flex-flow: column;
        }

        #header {
            background: #fff;
            color: #000;
        }

        #main {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
        }

        .menu {
            box-sizing: border-box;
            padding-bottom: 5px;
            padding-top: 32px;
            color: #585858;
            background-size: 22px 22px;
            background-position: center 8px;
            background-repeat: no-repeat;
        }

        .home {
            background-image: url(../../image/audit/one.jpg);
        }

        .video {
            background-image: url(../../image/audit/two.jpg);
        }

        .home.active {
            background-image: url(../../image/audit/one_act.png);
        }

        .video.active {
            background-image: url(../../image/audit/two_act.png);
        }

        #footer {
            background-color: #fff;
            width: 100%;
            text-align: center;
            border-top: #b2b2b2 solid 0.5px;
            color: #646464;
        }
    </style>
</head>

<body>
    <div id="wrap">
        <!-- <header id="header" class="aui-bar aui-bar-nav">{{text}}</header> -->
        <div id="main" class="flex-con"></div>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item home menu" tapmode v-for="(item, index) in menu" :key="index" :class="[item.class,{'active': activeId == item.id}]" @click="goMenu(item)">
                <div class="aui-bar-tab-label">{{item.text}}</div>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
    apiready = function() {
        init();
        FastClick.attach(document.body);
        api.refreshHeaderLoadDone()
            // 再点一次退出应用
        api.setStatusBarStyle({
            style: 'dark'
        });
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            api.toast({
                msg: '再点一次退出应用',
                duration: 2000,
                location: 'bottom'
            });
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                api.closeWidget({
                    silent: true
                });
            });
            setTimeout(function() {
                exitApp();
            }, 2000)
        });
        var vm = new Vue({
            el: '#wrap',
            data: {
                text: "借款",
                activeId: '0',
                menu: [{
                    name: 'index',
                    id: '0',
                    text: '借款',
                    link: 'index.html',
                    class: 'home',
                    active: true
                }, {
                    id: '1',
                    name: 'personal',
                    text: '个人中心',
                    link: 'personal.html',
                    class: 'video',
                    active: false
                }]
            },
            methods: {
                // 切换底部页面
                goMenu: function(item) {
                    item.active = true
                    this.activeId = item.id
                    this.text = item.text
                    api.openFrame({
                        name: item.name,
                        url: item.link,
                        bounces: false,
                        rect: {
                            x: 0,
                            y: 0,
                            w: 'auto',
                            h: mainPos.h - footerPos.h
                        }
                    });
                }
            },
            mounted: function() {
                // var rataData = $api.getStorage('rataData')
                // if (rataData) {
                //
                // } else {
                //     $api.setStorage('rataData', this.rataData)
                // }
            }
        })
    };

    var header, headerPos, main, mainPos, footer, footerPos

    function init() {
        // header = $api.byId('header');
        main = $api.byId('main');

        //适配iOS 7+，Android 4.4+状态栏
        $api.fixTabBar($api.byId('footer'))
            // $api.fixStatusBar(main);
            // headerPos = $api.offset(header);
        mainPos = $api.offset(main);
        footer = $api.byId('footer');
        footerPos = $api.offset(footer);
        api.openFrame({
            name: 'index',
            url: 'index.html',
            bounces: false,
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: mainPos.h - footerPos.h
            }
        });
    }


    // 再点一次退出应用
    function exitApp() {
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            api.toast({
                msg: '再点一次退出应用',
                duration: 2000,
                location: 'bottom'
            });
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                api.closeWidget({
                    silent: true
                });
            });
            setTimeout(function() {
                exitApp();
            }, 2000)
        });

    }
</script>

</html>
